﻿using System;
using Assets.Scripts.UI.View.Pause;
using UnityEngine;
using UnityEngine.UI;

namespace SizeboxUI
{
	// Token: 0x020003A3 RID: 931
	public class MainMenuSettingsController : MonoBehaviour
	{
		// Token: 0x170003AD RID: 941
		// (get) Token: 0x0600186A RID: 6250 RVA: 0x0009A80B File Offset: 0x00098A0B
		// (set) Token: 0x0600186B RID: 6251 RVA: 0x0009A813 File Offset: 0x00098A13
		public MenuController MainMenu
		{
			get
			{
				return this.mainMenu;
			}
			set
			{
				this.mainMenu = value;
			}
		}

		// Token: 0x0600186C RID: 6252 RVA: 0x0009A81C File Offset: 0x00098A1C
		private void Update()
		{
			if ((Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown(ButtonInput.EscapeAlt)) && !this.CloseIfOpen())
			{
				this.CloseSettings();
			}
		}

		// Token: 0x0600186D RID: 6253 RVA: 0x0009A84C File Offset: 0x00098A4C
		private bool CloseIfOpen()
		{
			bool result = false;
			if (this.gameSettings.activeSelf)
			{
				this.gameSettings.SetActive(false);
				result = true;
			}
			if (this.raygunSettings.activeSelf)
			{
				this.raygunSettings.SetActive(false);
				this.gameSettings.SetActive(true);
				return true;
			}
			if (this.videoSettings.activeSelf)
			{
				this.videoSettings.SetActive(false);
				result = true;
			}
			if (this.audioSettings.activeSelf)
			{
				this.audioSettings.SetActive(false);
				result = true;
			}
			return result;
		}

		// Token: 0x0600186E RID: 6254 RVA: 0x0009A8E0 File Offset: 0x00098AE0
		private void Start()
		{
			this.buttonPrefab = Resources.Load<Button>("UI/Pause/PauseButton");
			GameObject original = Resources.Load<GameObject>("UI/Pause/SettingsMenu");
			this.raygunSettings = UnityEngine.Object.Instantiate<GameObject>(original);
			this.raygunSettings.transform.SetParent(base.transform, false);
			RaygunSettingsView raygunSettingsView = this.raygunSettings.AddComponent<RaygunSettingsView>();
			this.raygunSettings.SetActive(false);
			this.aiGunSettings = UnityEngine.Object.Instantiate<GameObject>(original);
			this.aiGunSettings.transform.SetParent(base.transform, false);
			AIGunSettingsView aigunSettingsView = this.aiGunSettings.AddComponent<AIGunSettingsView>();
			this.aiGunSettings.SetActive(false);
			this.gameSettings = UnityEngine.Object.Instantiate<GameObject>(original);
			this.gameSettings.transform.SetParent(base.transform, false);
			this.gameSettings.AddComponent<GameSettingsView>().RaygunSettings = this.raygunSettings;
			this.gameSettings.GetComponent<GameSettingsView>().AIGunSettings = this.aiGunSettings;
			this.gameSettings.SetActive(false);
			raygunSettingsView._gameSettings = this.gameSettings;
			aigunSettingsView._gameSettings = this.gameSettings;
			this.videoSettings = UnityEngine.Object.Instantiate<GameObject>(original);
			this.videoSettings.transform.SetParent(base.transform, false);
			this.videoSettings.AddComponent<VideoSettingsView>();
			this.videoSettings.SetActive(false);
			this.audioSettings = UnityEngine.Object.Instantiate<GameObject>(original);
			this.audioSettings.transform.SetParent(base.transform, false);
			this.audioSettings.AddComponent<AudioSettingsView>();
			this.audioSettings.SetActive(false);
			this.buttonLayout = base.gameObject.GetComponentInChildren<GridLayoutGroup>();
			this.AddButton("Settings").onClick.AddListener(delegate()
			{
				this.OnSettingsClick();
			});
			this.AddButton("Video").onClick.AddListener(delegate()
			{
				this.OnVideoClick();
			});
			this.AddButton("Audio").onClick.AddListener(delegate()
			{
				this.OnAudioClick();
			});
			this.AddButton("Back").onClick.AddListener(delegate()
			{
				this.CloseSettings();
			});
		}

		// Token: 0x0600186F RID: 6255 RVA: 0x0009AAFC File Offset: 0x00098CFC
		private Button AddButton(string label)
		{
			Button button = UnityEngine.Object.Instantiate<Button>(this.buttonPrefab);
			button.transform.SetParent(this.buttonLayout.transform, false);
			button.gameObject.GetComponent<Text>().text = label;
			return button;
		}

		// Token: 0x06001870 RID: 6256 RVA: 0x0009AB3E File Offset: 0x00098D3E
		public void OnSettingsClick()
		{
			this.gameSettings.SetActive(true);
		}

		// Token: 0x06001871 RID: 6257 RVA: 0x0009AB4C File Offset: 0x00098D4C
		public void OnAudioClick()
		{
			this.audioSettings.SetActive(true);
		}

		// Token: 0x06001872 RID: 6258 RVA: 0x0009AB5A File Offset: 0x00098D5A
		public void OnVideoClick()
		{
			this.videoSettings.SetActive(true);
		}

		// Token: 0x06001873 RID: 6259 RVA: 0x0009AB68 File Offset: 0x00098D68
		public void CloseSettings()
		{
			this.mainMenu.menuUI.gameObject.SetActive(true);
			base.gameObject.SetActive(false);
		}

		// Token: 0x04001A91 RID: 6801
		private GameObject gameSettings;

		// Token: 0x04001A92 RID: 6802
		private GameObject raygunSettings;

		// Token: 0x04001A93 RID: 6803
		private GameObject aiGunSettings;

		// Token: 0x04001A94 RID: 6804
		private GameObject videoSettings;

		// Token: 0x04001A95 RID: 6805
		private GameObject audioSettings;

		// Token: 0x04001A96 RID: 6806
		private MenuController mainMenu;

		// Token: 0x04001A97 RID: 6807
		private Button buttonPrefab;

		// Token: 0x04001A98 RID: 6808
		private GridLayoutGroup buttonLayout;
	}
}
